package javase.swing;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;

/**
 * @author Dong
 *
 */
@SuppressWarnings({"rawtypes","unchecked"})
public class FirstSwing {
	public static void main(String[] args) {
		JFrame jFrame = new JFrame("???");
		JPanel jPanel = new JPanel();
		JButton jButton = new JButton("Click me!");
		JTextField jTextField = new JTextField("xxx");
		
		JComboBox jComboBox = new JComboBox();
		jButton.setBackground(Color.CYAN);
//		jButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED  ));
//		jButton.setBorder(BorderFactory.createEtchedBorder(Color.CYAN,Color.black));
//		jButton.setBorder(BorderFactory.createLoweredBevelBorder());
		jButton.addMouseListener(new MouseClick(jFrame));
		System.out.println("timer is waiting for starting...");
//		jButton.addActionListener(new B(jTextField));
		jComboBox.addItem("111");
		jComboBox.addItem("222");
		jPanel.add(jComboBox);
		jPanel.add(jButton);
		jPanel.add(jTextField);
		jFrame.add(jPanel);
		jFrame.setSize(600, 300);
		jFrame.setLocation(50, 50);
		jFrame.setVisible(true);
		Timer t = new Timer(3000, new ChangeAct(jTextField) );
		t.start();
		t.setRepeats(false);
	}
}
class ChangeAct implements ActionListener{
	private JTextField jTextField;
	public ChangeAct(JTextField jTextField){
		this.jTextField = jTextField;
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
		System.out.println("timer is started...");
		jTextField.setText("changing...");
	}
}
class MouseClick extends MouseAdapter{
	private JFrame jFrame;
	public MouseClick(JFrame jFrame) {
		this.jFrame = jFrame;
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		jFrame.dispose();
	}
	
}